package cn.sxgan.core.controller;

import cn.sxgan.common.anno.RequestAroundLog;
import cn.sxgan.common.anno.WorkTime;
import cn.sxgan.common.entity.query.SysMenuQuery;
import cn.sxgan.common.entity.query.SysUserQuery;
import cn.sxgan.common.entity.sys.PageRequest;
import cn.sxgan.common.entity.vo.SysMenuVO;
import cn.sxgan.common.entity.vo.SysRoleAndMenuVO;
import cn.sxgan.common.entity.vo.SysRoleVO;
import cn.sxgan.common.entity.vo.SysUserAndRoleVO;
import cn.sxgan.common.entity.vo.SysUserVO;
import cn.sxgan.common.response.Result;
import cn.sxgan.core.controller.api.IUserMenuController;
import cn.sxgan.core.services.impl.MenuServiceImpl;
import cn.sxgan.core.services.impl.UserServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Description: 用户菜单控制器
 * @Author: sxgan
 * @Date: 2024-11-12 14:18
 * @Version: 1.0
 **/
@RestController
@Slf4j
@RequestMapping("/user")
public class UserMenuController implements IUserMenuController {
    
    @Autowired
    UserServiceImpl userService;
    
    @Autowired
    MenuServiceImpl menuService;
    
    @WorkTime("获取用户列表")
    @GetMapping("/findUserList")
    public Result<List<SysUserVO>> findUserList(@ModelAttribute SysUserQuery sysUserQuery) {
        return userService.findUserList(sysUserQuery);
    }
    
    @WorkTime("用户更新")
    @PostMapping("/updateSysUserInfo")
    public Result<String> updateSysUserInfo(@RequestBody SysUserVO sysUserVO) {
        return userService.updateSysUserInfo(sysUserVO);
    }
    
    @WorkTime("删除用户")
    @GetMapping("/removeUser")
    public Result<String> removeUser(@RequestParam Long userId) {
        return userService.removeUser(userId);
    }
    
    @WorkTime("获取用户角色列表")
    @GetMapping("/findUserRoleList")
    public Result<List<SysUserAndRoleVO>> findUserRoleList(@ModelAttribute SysUserQuery sysUserQuery) {
        return userService.findUserRoleList(sysUserQuery);
    }
    
    @WorkTime("获取角色列表")
    @RequestAroundLog
    @GetMapping("/findRoleList")
    public Result<List<SysRoleVO>> findRoleList(@ModelAttribute PageRequest pageRequest) {
        return userService.findRoleList(pageRequest);
    }
    
    
    @WorkTime("新增角色")
    @RequestAroundLog
    @PostMapping("/addRole")
    public Result<String> addRole(@RequestBody SysRoleVO sysRoleVO) {
        return userService.addRole(sysRoleVO);
    }
    
    @WorkTime("编辑角色")
    @RequestAroundLog
    @PostMapping("/editRole")
    public Result<String> editRole(@RequestBody SysRoleVO sysRoleVO) {
        return userService.editRole(sysRoleVO);
    }
    
    @WorkTime("移除角色")
    @RequestAroundLog
    @PostMapping("/removeRole")
    public Result<String> removeRole(@RequestParam List<Long> roleIds) {
        return userService.removeRole(roleIds);
    }
    
    @WorkTime("绑定用户角色")
    @RequestAroundLog
    @GetMapping("/bindUserAndRole")
    public Result<String> bindUserAndRole(@RequestParam Long userId, @RequestParam Long roleId) {
        return userService.bindUserAndRole(userId, roleId);
    }
    
    @WorkTime("获取菜单列表")
    @RequestAroundLog
    @GetMapping("/findMenuList")
    public Result<List<SysMenuVO>> findMenuList(@ModelAttribute SysMenuQuery sysMenuQuery) {
        return menuService.findMenuList(sysMenuQuery);
    }
    
    
    @WorkTime("添加菜单")
    @RequestAroundLog
    @PostMapping("/addMenu")
    public Result<String> addMenu(@RequestBody SysMenuVO sysMenuVO) {
        return menuService.addMenu(sysMenuVO);
    }
    
    @WorkTime("编辑菜单")
    @RequestAroundLog
    @PostMapping("/editMenu")
    public Result<String> editMenu(@RequestBody SysMenuVO sysMenuVO) {
        return menuService.editMenu(sysMenuVO);
    }
    
    @WorkTime("移除菜单")
    @RequestAroundLog
    @PostMapping("/removeMenu")
    public Result<String> removeMenu(@RequestParam List<Long> menuIds) {
        return menuService.removeMenu(menuIds);
    }
    
    @WorkTime("绑定角色菜单")
    @RequestAroundLog
    @PostMapping("/bindRoleAndMenu")
    public Result<String> bindRoleAndMenu(@RequestParam Long roleId, @RequestParam List<Long> menuIdList) {
        return menuService.bindRoleAndMenu(roleId, menuIdList);
    }
    
    @WorkTime("获取角色菜单列表")
    @GetMapping("/findRoleMenuList")
    public Result<List<SysRoleAndMenuVO>> findRoleMenuList(@ModelAttribute PageRequest pageRequest) {
        return userService.findRoleMenuList(pageRequest);
    }
    
    @WorkTime("查询当前用户菜单")
    @GetMapping("/findUserMenus")
    public Result<List> findUserMenus() {
        return userService.findUserMenus();
    }
}
